package q27_removeElement;

import java.util.Arrays;

public class Solution_1 {
    public static void main(String[] args) {
        int[] nums = {};
        System.out.println(removeElement(nums,1));
        System.out.println(Arrays.toString(nums));
    }

    public static int removeElement(int[] nums, int val) {


        int p1 = 0;
        int p2 = 0;

        // 设置两个指针，分别用来检测和替换
        for (; p2 < nums.length; p2++) {
            if(nums[p2] != val){
                nums[p1] = nums[p2];
                p1 ++;
            }
        }

        return p1 ;
    }
}
